<?php

namespace app\controller;



use app\model\PhoneDn;
use app\service\UserService;
use library\wechat;
use library\wx_pay;
use support\Http;
use support\Redis;
use support\Request;

class IndexController
{
    protected array $noNeedLogin = ['index', 'test', 'notify'];

    public function index(Request $request)
    {


        return view('index/view', ['name' => 'webman']);
    }

    public function notify(Request $request)
    {
        $token = 'qq19951202'; // 在微信后台填写的Token值
        var_dump($request->all());
        $signature = $request->get('signature');
        $timestamp = $request->get('timestamp');
        $nonce = $request->get('nonce');
        $echostr = $request->get('echostr');

        $tmpArr = [$token, $timestamp, $nonce];
        sort($tmpArr, SORT_STRING);
        $tmpStr = implode($tmpArr);
        $tmpStr = sha1($tmpStr);

        if ($tmpStr === $signature) {
            return response($echostr); // 验证通过，返回 echostr
        } else {
            return response('verify fail'); // 验证失败
        }


    }


    //查询当前可用分机信息
    public function test(Request $request)
    {





        $access_token = wechat::get_access_token();
        wechat::get_wxa_code($access_token, 202, 'user_id');

        /*for ($i = 1000; $i < 5000; $i++) {
            PhoneDn::create([
                'dn' => $i,
            ]);
        }

        for ($i = 6000; $i < 10000; $i++) {
            PhoneDn::create([
                'dn' => $i,
            ]);
        }*/
        /*$res =    (new WxShopService())->wxShopOrderUpdate('channels_ec_order_pay', '3729872309645358848');

        return json($res);*/

    }

    //使用教程
    public function tutorial(Request $request)
    {
        $list = [
            [
                'desc' => '1.微信扫码绑定信息',
                'imgUrl' => 'https://hennan-sanjiaomao.oss-cn-beijing.aliyuncs.com/uploads/jc/1.jpg',
            ],
            [
                'desc' => '2.揭开表层保护膜',
                'imgUrl' => 'https://hennan-sanjiaomao.oss-cn-beijing.aliyuncs.com/uploads/jc/2.jpg',
            ],
            [
                'desc' => '3.从车内贴在前挡风上',
                'imgUrl' => 'https://hennan-sanjiaomao.oss-cn-beijing.aliyuncs.com/uploads/jc/3.jpg',
            ],
            [
                'desc' => '4.启用成功',
                'imgUrl' => 'https://hennan-sanjiaomao.oss-cn-beijing.aliyuncs.com/uploads/jc/4.jpg',
            ]
        ];


        $res = [
            'is_use' => false,
            'list' => $list
        ];


        return json(apiSuccess($res));

    }


    public function json(Request $request)
    {
        $res = (new Http())->get('https://www.baidu.com', [
            'wd' => 'aaa',
        ]);
        return json(apiSuccess([$res]));
    }
}
